package com.takeoutsystem.support;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * cookie操作相关类
 */
public class CookieUtil {
    /**
     * 通过key获取cookie的value
     * @param key
     * @param request
     * @return
     */
    public static String getValueByKey(String key, HttpServletRequest request){
        String value=null;
        Cookie[] cookies=request.getCookies();

       for(Cookie cookie : cookies){
           if(cookie.getName().equals(key)){
              value= cookie.getValue();
              break;
           }
       }
       return value;
    }
}
